
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 09/09/2014 20:13:22
-- Generated from EDMX file: D:\job\P2C\jxfinancial\P2PWeb\Models\P2PModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [P2PModel];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_FlightCampaign]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FlightSet] DROP CONSTRAINT [FK_FlightCampaign];
GO
IF OBJECT_ID(N'[dbo].[FK_AccountCampaign]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CampaignSet] DROP CONSTRAINT [FK_AccountCampaign];
GO
IF OBJECT_ID(N'[dbo].[FK_AccountFlight]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FlightSet] DROP CONSTRAINT [FK_AccountFlight];
GO
IF OBJECT_ID(N'[dbo].[FK_CampUpLoadCampaign]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CampUpLoadSet] DROP CONSTRAINT [FK_CampUpLoadCampaign];
GO
IF OBJECT_ID(N'[dbo].[FK_AccountAuthenticationAccount]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AccountSet] DROP CONSTRAINT [FK_AccountAuthenticationAccount];
GO
IF OBJECT_ID(N'[dbo].[FK_AccountInfoAccount]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AccountSet] DROP CONSTRAINT [FK_AccountInfoAccount];
GO
IF OBJECT_ID(N'[dbo].[FK_WorkInfoAccount]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AccountSet] DROP CONSTRAINT [FK_WorkInfoAccount];
GO
IF OBJECT_ID(N'[dbo].[FK_ContactInfoAccount]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AccountSet] DROP CONSTRAINT [FK_ContactInfoAccount];
GO
IF OBJECT_ID(N'[dbo].[FK_AccountAuditingAccount]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AccountAuditingSet] DROP CONSTRAINT [FK_AccountAuditingAccount];
GO
IF OBJECT_ID(N'[dbo].[FK_CampaignAuditingCampaign]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CampaignAuditingSet] DROP CONSTRAINT [FK_CampaignAuditingCampaign];
GO
IF OBJECT_ID(N'[dbo].[FK_AccountAgent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AccountSet] DROP CONSTRAINT [FK_AccountAgent];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[AccountSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AccountSet];
GO
IF OBJECT_ID(N'[dbo].[CampaignSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CampaignSet];
GO
IF OBJECT_ID(N'[dbo].[FlightSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FlightSet];
GO
IF OBJECT_ID(N'[dbo].[AgentSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AgentSet];
GO
IF OBJECT_ID(N'[dbo].[AccountAuthenticationSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AccountAuthenticationSet];
GO
IF OBJECT_ID(N'[dbo].[AccountInfoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AccountInfoSet];
GO
IF OBJECT_ID(N'[dbo].[MediaProducts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MediaProducts];
GO
IF OBJECT_ID(N'[dbo].[CampUpLoadSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CampUpLoadSet];
GO
IF OBJECT_ID(N'[dbo].[WorkInfoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WorkInfoSet];
GO
IF OBJECT_ID(N'[dbo].[ContactInfoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContactInfoSet];
GO
IF OBJECT_ID(N'[dbo].[AccountAuditingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AccountAuditingSet];
GO
IF OBJECT_ID(N'[dbo].[CampaignAuditingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CampaignAuditingSet];
GO
IF OBJECT_ID(N'[dbo].[RechargeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RechargeSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'AccountSet'
CREATE TABLE [dbo].[AccountSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IsDel] bit  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [PassWord] nvarchar(max)  NOT NULL,
    [Status] int  NOT NULL,
    [CreationTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL,
    [Type] int  NOT NULL,
    [Money] decimal(18,2)  NOT NULL,
    [Mobile] nvarchar(max)  NULL,
    [Email] nvarchar(max)  NULL,
    [AgentID] int  NULL,
    [AccountAuthentication_ID] int  NULL,
    [AccountInfo_ID] int  NULL,
    [WorkInfo_ID] int  NULL,
    [ContactInfo_ID] int  NULL
);
GO

-- Creating table 'CampaignSet'
CREATE TABLE [dbo].[CampaignSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [StartDate] datetime  NOT NULL,
    [EndDate] datetime  NOT NULL,
    [IsDel] bit  NOT NULL,
    [Status] int  NOT NULL,
    [CreationTime] datetime  NULL,
    [CreationUser] nvarchar(max)  NULL,
    [UpdateTime] datetime  NULL,
    [UpdateUser] nvarchar(max)  NULL,
    [InterestRate] float  NOT NULL,
    [Amount] int  NOT NULL,
    [Type] int  NOT NULL,
    [CalcType] int  NOT NULL,
    [RealAmount] int  NOT NULL,
    [Info] nvarchar(max)  NOT NULL,
    [AccountID] int  NOT NULL,
    [AgentID] int  NULL,
    [DueDate] datetime  NULL,
    [Mortgage] int  NOT NULL,
    [IsJvb] bit  NOT NULL
);
GO

-- Creating table 'FlightSet'
CREATE TABLE [dbo].[FlightSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [CampaignID] int  NOT NULL,
    [CreationTime] datetime  NULL,
    [UpdateTime] datetime  NULL,
    [Amount] int  NOT NULL,
    [AccountID] int  NOT NULL,
    [IsDel] bit  NOT NULL,
    [UpdateUser] nvarchar(max)  NULL
);
GO

-- Creating table 'AgentSet'
CREATE TABLE [dbo].[AgentSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IsDel] bit  NOT NULL,
    [Name] nvarchar(max)  NULL,
    [CreationTime] datetime  NULL,
    [CreationUser] nvarchar(max)  NULL,
    [UpdateTime] datetime  NULL,
    [UpdateUser] nvarchar(max)  NULL,
    [CreationUserID] int  NULL,
    [UpdateUserID] int  NULL,
    [AgentType] nvarchar(max)  NULL,
    [Url] nvarchar(max)  NULL,
    [Address] nvarchar(max)  NOT NULL,
    [Ratio] float  NOT NULL
);
GO

-- Creating table 'AccountAuthenticationSet'
CREATE TABLE [dbo].[AccountAuthenticationSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IDCard] nvarchar(max)  NOT NULL,
    [IDCardUrl] nvarchar(max)  NOT NULL,
    [Status] int  NOT NULL,
    [IDCardUrlNegative] nvarchar(max)  NOT NULL,
    [RealName] nvarchar(max)  NOT NULL,
    [CreditReportUrl] nvarchar(max)  NULL,
    [JobUrl] nvarchar(max)  NULL,
    [HomeUrl] nvarchar(max)  NULL,
    [WorkUrl] nvarchar(max)  NULL,
    [HeadUrl] nvarchar(max)  NULL
);
GO

-- Creating table 'AccountInfoSet'
CREATE TABLE [dbo].[AccountInfoSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Sex] int  NULL,
    [Age] int  NULL,
    [Education] int  NULL,
    [Marital] int  NULL,
    [Property] int  NULL,
    [ProvincialID] int  NULL,
    [CityID] int  NULL,
    [CountyID] int  NULL,
    [AreaName] nvarchar(max)  NULL,
    [CreditQuota] int  NULL
);
GO

-- Creating table 'MediaProducts'
CREATE TABLE [dbo].[MediaProducts] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [IsDel] bit  NOT NULL,
    [Amount] decimal(18,0)  NOT NULL,
    [CalcType] int  NOT NULL,
    [LoanPeriod] datetime  NULL,
    [Name] nvarchar(max)  NULL,
    [Status] nvarchar(max)  NULL,
    [Type] nvarchar(max)  NULL,
    [StartDate] datetime  NOT NULL,
    [EndDate] datetime  NOT NULL,
    [CreationTime] datetime  NULL,
    [CreationUser] nvarchar(max)  NULL,
    [UpdateTime] datetime  NULL,
    [UpdateUser] nvarchar(max)  NULL
);
GO

-- Creating table 'CampUpLoadSet'
CREATE TABLE [dbo].[CampUpLoadSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [CampaignID] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Type] int  NOT NULL,
    [Status] int  NOT NULL,
    [IsDel] bit  NOT NULL,
    [UpLoad] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'WorkInfoSet'
CREATE TABLE [dbo].[WorkInfoSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [CompanyName] nvarchar(max)  NULL,
    [ProvincialID] int  NULL,
    [CityID] int  NULL,
    [CountyID] int  NULL,
    [AreaName] nvarchar(max)  NULL,
    [Phone] nvarchar(max)  NULL,
    [WorkDate] datetime  NULL,
    [Department] nvarchar(max)  NULL,
    [Job] nvarchar(max)  NULL,
    [CompanyType] int  NULL
);
GO

-- Creating table 'ContactInfoSet'
CREATE TABLE [dbo].[ContactInfoSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [FamilyContact] nvarchar(max)  NULL,
    [FamilyRelation] int  NULL,
    [FamilyPhone] nvarchar(max)  NULL,
    [WorkContact] nvarchar(max)  NULL,
    [WorkRelation] int  NULL,
    [WorkPhone] nvarchar(max)  NULL,
    [OtherContact] nvarchar(max)  NULL,
    [OtherRelation] int  NULL,
    [OtherPhone] nvarchar(max)  NULL
);
GO

-- Creating table 'AccountAuditingSet'
CREATE TABLE [dbo].[AccountAuditingSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [UpdateTime] datetime  NOT NULL,
    [CreationTime] datetime  NOT NULL,
    [CreationUser] nvarchar(max)  NULL,
    [UpdateUser] nvarchar(max)  NULL,
    [Type] int  NOT NULL,
    [Remark] nvarchar(max)  NOT NULL,
    [AccountID] int  NOT NULL
);
GO

-- Creating table 'CampaignAuditingSet'
CREATE TABLE [dbo].[CampaignAuditingSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [UpdateTime] datetime  NOT NULL,
    [CreationTime] datetime  NOT NULL,
    [CreationUser] nvarchar(max)  NULL,
    [UpdateUser] nvarchar(max)  NULL,
    [Type] int  NOT NULL,
    [Remark] nvarchar(max)  NOT NULL,
    [CampaignID] int  NOT NULL
);
GO

-- Creating table 'RechargeSet'
CREATE TABLE [dbo].[RechargeSet] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [AccountID] int  NOT NULL,
    [OrderID] nvarchar(max)  NOT NULL,
    [Type] int  NOT NULL,
    [Money] decimal(18,2)  NOT NULL,
    [CreationTime] datetime  NOT NULL,
    [Status] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'AccountSet'
ALTER TABLE [dbo].[AccountSet]
ADD CONSTRAINT [PK_AccountSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'CampaignSet'
ALTER TABLE [dbo].[CampaignSet]
ADD CONSTRAINT [PK_CampaignSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'FlightSet'
ALTER TABLE [dbo].[FlightSet]
ADD CONSTRAINT [PK_FlightSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'AgentSet'
ALTER TABLE [dbo].[AgentSet]
ADD CONSTRAINT [PK_AgentSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'AccountAuthenticationSet'
ALTER TABLE [dbo].[AccountAuthenticationSet]
ADD CONSTRAINT [PK_AccountAuthenticationSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'AccountInfoSet'
ALTER TABLE [dbo].[AccountInfoSet]
ADD CONSTRAINT [PK_AccountInfoSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MediaProducts'
ALTER TABLE [dbo].[MediaProducts]
ADD CONSTRAINT [PK_MediaProducts]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'CampUpLoadSet'
ALTER TABLE [dbo].[CampUpLoadSet]
ADD CONSTRAINT [PK_CampUpLoadSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'WorkInfoSet'
ALTER TABLE [dbo].[WorkInfoSet]
ADD CONSTRAINT [PK_WorkInfoSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ContactInfoSet'
ALTER TABLE [dbo].[ContactInfoSet]
ADD CONSTRAINT [PK_ContactInfoSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'AccountAuditingSet'
ALTER TABLE [dbo].[AccountAuditingSet]
ADD CONSTRAINT [PK_AccountAuditingSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'CampaignAuditingSet'
ALTER TABLE [dbo].[CampaignAuditingSet]
ADD CONSTRAINT [PK_CampaignAuditingSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'RechargeSet'
ALTER TABLE [dbo].[RechargeSet]
ADD CONSTRAINT [PK_RechargeSet]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CampaignID] in table 'FlightSet'
ALTER TABLE [dbo].[FlightSet]
ADD CONSTRAINT [FK_FlightCampaign]
    FOREIGN KEY ([CampaignID])
    REFERENCES [dbo].[CampaignSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FlightCampaign'
CREATE INDEX [IX_FK_FlightCampaign]
ON [dbo].[FlightSet]
    ([CampaignID]);
GO

-- Creating foreign key on [AccountID] in table 'CampaignSet'
ALTER TABLE [dbo].[CampaignSet]
ADD CONSTRAINT [FK_AccountCampaign]
    FOREIGN KEY ([AccountID])
    REFERENCES [dbo].[AccountSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AccountCampaign'
CREATE INDEX [IX_FK_AccountCampaign]
ON [dbo].[CampaignSet]
    ([AccountID]);
GO

-- Creating foreign key on [AccountID] in table 'FlightSet'
ALTER TABLE [dbo].[FlightSet]
ADD CONSTRAINT [FK_AccountFlight]
    FOREIGN KEY ([AccountID])
    REFERENCES [dbo].[AccountSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AccountFlight'
CREATE INDEX [IX_FK_AccountFlight]
ON [dbo].[FlightSet]
    ([AccountID]);
GO

-- Creating foreign key on [CampaignID] in table 'CampUpLoadSet'
ALTER TABLE [dbo].[CampUpLoadSet]
ADD CONSTRAINT [FK_CampUpLoadCampaign]
    FOREIGN KEY ([CampaignID])
    REFERENCES [dbo].[CampaignSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CampUpLoadCampaign'
CREATE INDEX [IX_FK_CampUpLoadCampaign]
ON [dbo].[CampUpLoadSet]
    ([CampaignID]);
GO

-- Creating foreign key on [AccountAuthentication_ID] in table 'AccountSet'
ALTER TABLE [dbo].[AccountSet]
ADD CONSTRAINT [FK_AccountAuthenticationAccount]
    FOREIGN KEY ([AccountAuthentication_ID])
    REFERENCES [dbo].[AccountAuthenticationSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AccountAuthenticationAccount'
CREATE INDEX [IX_FK_AccountAuthenticationAccount]
ON [dbo].[AccountSet]
    ([AccountAuthentication_ID]);
GO

-- Creating foreign key on [AccountInfo_ID] in table 'AccountSet'
ALTER TABLE [dbo].[AccountSet]
ADD CONSTRAINT [FK_AccountInfoAccount]
    FOREIGN KEY ([AccountInfo_ID])
    REFERENCES [dbo].[AccountInfoSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AccountInfoAccount'
CREATE INDEX [IX_FK_AccountInfoAccount]
ON [dbo].[AccountSet]
    ([AccountInfo_ID]);
GO

-- Creating foreign key on [WorkInfo_ID] in table 'AccountSet'
ALTER TABLE [dbo].[AccountSet]
ADD CONSTRAINT [FK_WorkInfoAccount]
    FOREIGN KEY ([WorkInfo_ID])
    REFERENCES [dbo].[WorkInfoSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WorkInfoAccount'
CREATE INDEX [IX_FK_WorkInfoAccount]
ON [dbo].[AccountSet]
    ([WorkInfo_ID]);
GO

-- Creating foreign key on [ContactInfo_ID] in table 'AccountSet'
ALTER TABLE [dbo].[AccountSet]
ADD CONSTRAINT [FK_ContactInfoAccount]
    FOREIGN KEY ([ContactInfo_ID])
    REFERENCES [dbo].[ContactInfoSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContactInfoAccount'
CREATE INDEX [IX_FK_ContactInfoAccount]
ON [dbo].[AccountSet]
    ([ContactInfo_ID]);
GO

-- Creating foreign key on [AccountID] in table 'AccountAuditingSet'
ALTER TABLE [dbo].[AccountAuditingSet]
ADD CONSTRAINT [FK_AccountAuditingAccount]
    FOREIGN KEY ([AccountID])
    REFERENCES [dbo].[AccountSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AccountAuditingAccount'
CREATE INDEX [IX_FK_AccountAuditingAccount]
ON [dbo].[AccountAuditingSet]
    ([AccountID]);
GO

-- Creating foreign key on [CampaignID] in table 'CampaignAuditingSet'
ALTER TABLE [dbo].[CampaignAuditingSet]
ADD CONSTRAINT [FK_CampaignAuditingCampaign]
    FOREIGN KEY ([CampaignID])
    REFERENCES [dbo].[CampaignSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CampaignAuditingCampaign'
CREATE INDEX [IX_FK_CampaignAuditingCampaign]
ON [dbo].[CampaignAuditingSet]
    ([CampaignID]);
GO

-- Creating foreign key on [AgentID] in table 'AccountSet'
ALTER TABLE [dbo].[AccountSet]
ADD CONSTRAINT [FK_AccountAgent]
    FOREIGN KEY ([AgentID])
    REFERENCES [dbo].[AgentSet]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AccountAgent'
CREATE INDEX [IX_FK_AccountAgent]
ON [dbo].[AccountSet]
    ([AgentID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------